﻿using System;
using System.Collections.Generic;
using System.IO;

namespace HslCommunication.LogNet
{
	/// <summary>
	/// 基于路径实现的日志类的基类，提供几个基础的方法信息。<br />
	/// The base class of the log class implemented based on the path provides several basic method information.
	/// </summary>
	// Token: 0x020000D7 RID: 215
	public abstract class LogPathBase : LogNetBase
	{
		/// <inheritdoc />
		// Token: 0x06001108 RID: 4360 RVA: 0x00061900 File Offset: 0x0005FB00
		protected override void OnWriteCompleted()
		{
			bool flag = this.controlFileQuantity > 1;
			if (flag)
			{
				try
				{
					string[] existLogFileNames = this.GetExistLogFileNames();
					bool flag2 = existLogFileNames.Length > this.controlFileQuantity;
					if (flag2)
					{
						List<FileInfo> list = new List<FileInfo>();
						for (int i = 0; i < existLogFileNames.Length; i++)
						{
							list.Add(new FileInfo(existLogFileNames[i]));
						}
						list.Sort((FileInfo m, FileInfo n) => m.CreationTime.CompareTo(n.CreationTime));
						for (int j = 0; j < list.Count - this.controlFileQuantity; j++)
						{
							File.Delete(list[j].FullName);
						}
					}
				}
				catch
				{
				}
			}
		}

		/// <summary>
		/// 返回所有的日志文件名称，返回一个列表<br />
		/// Returns all log file names, returns a list
		/// </summary>
		/// <returns>所有的日志文件信息</returns>
		// Token: 0x06001109 RID: 4361 RVA: 0x000619E4 File Offset: 0x0005FBE4
		public string[] GetExistLogFileNames()
		{
			bool flag = !string.IsNullOrEmpty(this.filePath);
			string[] result;
			if (flag)
			{
				result = Directory.GetFiles(this.filePath, "Logs_*.txt");
			}
			else
			{
				result = new string[0];
			}
			return result;
		}

		/// <inheritdoc />
		// Token: 0x0600110A RID: 4362 RVA: 0x00061A21 File Offset: 0x0005FC21
		public override string ToString()
		{
			return "LogPathBase";
		}

		/// <summary>
		/// 当前正在存储的文件名<br />
		/// File name currently being stored
		/// </summary>
		// Token: 0x04000458 RID: 1112
		protected string fileName = string.Empty;

		/// <summary>
		/// 存储文件的路径，如果设置为空，就不进行存储。<br />
		/// The path for storing the file. If it is set to empty, it will not be stored.
		/// </summary>
		// Token: 0x04000459 RID: 1113
		protected string filePath = string.Empty;

		/// <summary>
		/// 控制文件的数量，小于1则不进行任何操作，当设置为10的时候，就限制文件数量为10。<br />
		/// Control the number of files. If it is less than 1, no operation is performed. When it is set to 10, the number of files is limited to 10.
		/// </summary>
		// Token: 0x0400045A RID: 1114
		protected int controlFileQuantity = -1;
	}
}
